home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 5 / olaf.zip / OLAF.DOC next >
Text File  |  1986-01-12  |  63KB  |  1,416 lines

  1.                                          (tm)
  2.                                      OLAF
  3.  
  4.                                 Copyright(c) 1986
  5.  
  6.                                       by
  7.                                 A.  D.  Clark
  8.                                 2119 Ridge Avenue
  9.                                 Evanston, IL 60201
  10.                                 U.S.A.
  11.  
  12.                                   Version 1.0
  13.  
  14.  
  15. I.  Introduction
  16.  
  17.     OLAF  stands  for  "On  Line  Access  of  Files".   It  is  a data base
  18.     management program  developed  especially  for  transaction  processing
  19.     applications  on personal computers.  Transaction process is defined to
  20.     be the set of data processing applications in which transaction records
  21.     of one file are used to make changes to the  records  of  one  or  more
  22.     other  files.  In addition to its transaction processing features, OLAF
  23.     has powerful inquiry and reporting features.
  24.  
  25.     OLAF is executed using its own command language.  With  a  few  of  its
  26.     brief  commands it can do things which it would take entire programs to
  27.     do in languages like COBOL and C.  Its interactive mode makes  it  easy
  28.     to learn and use.
  29.  
  30. II. OLAF Cribsheet
  31.  
  32.     The cribsheet is meant to be printed and  referred  to  as  an  aid  in
  33.     using OLAF.
  34.  
  35.         Commands        Options         Special Characters
  36.         --------        -------         ------------------
  37.         Add             Silence         // Carriage Return
  38.         Build           To              [] Blank
  39.         Change          Find            "" Quote
  40.         Constant        Nocarriage      <- Backspace
  41.         Declare         Repeat          |  Tab
  42.         Delete          Noise           =  Assignment
  43.         End             Nowrite         /* .. */  Comment Delimiters
  44.         Execute         Page            ( .. ) Expression Delimiters
  45.         Fields                          { .. } Statement Delimiters
  46.         File                            &  Line Continuation Symbol
  47.         Final           Modifiers       ^ .. ^ Modifier Delimiters
  48.         Heading         ---------
  49.         Let             n.d
  50.         New             Descending
  51.         Open            Variable
  52.         Print           Code
  53.         Proc            Comma
  54.         Redefine        DDMMMYYYY       Arithmetic Operators
  55.         Reset           MM/DD/YY        --------------------
  56.         Select                          +  Addition
  57.         Sort                            -  Subtraction
  58.         Title                           *  Multiplication
  59.                                         /  Division
  60.         Relational Operators            ** Exponentiation
  61.         --------------------            ^/ Square Root
  62.         =  Equality
  63.         != Inequality                   Statment Commands
  64.         >  Greater Than                 -----------------
  65.         <  Less Than                    IF condition THEN statement
  66.         <= Less Than, Equal To             ELSE statement
  67.         >= Greater Than, Equal          WHILE condition DO statement
  68.                                         CALL procedure
  69.                                         TTY field-name
  70.         Alpha Arithmetic
  71.         ----------------                Compound Condition Conjunctions
  72.         +  Concatenation                -------------------------------
  73.         *  Propogation                  AND
  74.                                         OR
  75.         Date Arithmetic
  76.         ---------------
  77.         +  Addition
  78.         -  Subtraction
  79.  
  80.         File            Byte
  81.         Field Types     Size            Range
  82.         -----------     ----            -----
  83.         Short            1              0 through +255
  84.         Int              2              -32,768 through +32,767
  85.         Unsigned         2              0 through 65,535
  86.         Long             4              -2,147,483,648 - +2,147,483,647
  87.         Float            4              Large numbers, no decimals.
  88.         Double           8              Large numbers, decimals allowed.
  89.         Coded            1              0 through +255
  90.         Date             4              Year 0 through +5,772,805
  91.         Alpha            Equal to the
  92.                          specified
  93.                          number of
  94.                          characters.
  95.  
  96.         Temporary Variables
  97.         Field Types
  98.         -----------
  99.         Long             Sizes and ranges for temporary variables are
  100.         Double           the same as for file fields.
  101.         Alpha
  102.         Date
  103.  
  104.         File Definition Options
  105.         -----------------------
  106.         Minimum
  107.         Maximum
  108.         Decimals  <number of decimals in I-O for a double>
  109.         Code      <size /g the code name for a coded field>
  110.         Mult      <number of list entries for a coded field>
  111.         Pname     <size of the print name for a coded field>
  112.  
  113.  
  114. II.  Command Syntax Summary
  115.  
  116.     The underscores indicate the parts of  the  command  element  that  are
  117.     required.   The square brackets where they are not underscored indicate
  118.     optional command elements
  119.  
  120. A.  Main Level Commands
  121.     -------------------
  122.  
  123.     Any of the following commands are valid after the "*" prompt.
  124.  
  125. ADD
  126. -
  127.  
  128. BUILD [/<options>/] <filename>
  129. -      -         -
  130.  
  131. CHANGE [/<options>/] IF <condition> THEN { <statement> } [ELSE] <statement>, ...
  132. -       -         -  -- ----------- ---- -             -
  133.  
  134. CONSTANT <varname> = <value>, ...
  135. --       --------- - -------
  136.  
  137. DECLARE <variable type> <varname> [[<dimension>]] = <value>, ...
  138. -       --------------  ---------  -           -
  139.  
  140. DECLARE ALPHA <varname> [<<field size>>] [[<dimension>]] = <value>, ...
  141. -       -                -            -   -           -
  142.  
  143. DELETE [/<options>/] [IF] <condition>
  144. ---     -         -       -----------
  145.  
  146. END
  147. -
  148.  
  149. EXECUTE [/<options>/] <filename>
  150. --       -         -  ----------
  151.  
  152. FIELDS [/<options>/]
  153. -       -         -
  154.  
  155. FILE <file reference number>
  156. ---  -----------------------
  157.  
  158. FINAL <statement>, ...
  159. ---
  160.  
  161. HEADING <statement>, ...
  162. -
  163.  
  164. LET <statement>, ...
  165. -
  166.  
  167. NEW <filename>
  168. -   ----------
  169.  
  170. OPEN <filename>, ...
  171. -    ----------
  172.  
  173. PRINT [/<options>/] <statement>, ...
  174. -      -         -
  175.  
  176. PROC <procedure name> <file reference number>
  177. ---  ---------------- -----------------------
  178.  
  179. REDEFINE
  180. ---
  181.  
  182. RESET
  183. -
  184.  
  185. SELECT [/<options>/] [IF] <condition>
  186. -       -         -       -----------
  187.  
  188. SORT [/<options>/] <statement>, ...
  189. --    -         -
  190.  
  191. TITLE <statement>, ...
  192. -
  193.  
  194. B.  Redefinition Level Commands
  195.     ---------------------------
  196.  
  197.     Any of the following commands are valid after the ">>" prompt.
  198.  
  199. ADD CODE  <field name> "<code name>" = "<print name>"
  200. -   -     ------------ ------------- - --------------
  201.  
  202. ADD FIELDS
  203. -   -
  204.  
  205. ADD NAME <existing field name> <new field name>
  206. -   -    --------------------- ----------------
  207.  
  208. CHANGE CODE <field name> "<code or print name>" [=] "<code or print name>"
  209. --     -    -----------  ----------------------     ----------------------
  210.  
  211. CHANGE MAXIMUM <field name> <number or date>
  212. --     --      ------------ ----------------
  213.  
  214. CHANGE MINIMUM <field name> <number or date>
  215. --     -       ------------ ----------------
  216.  
  217. CHANGE MULT <coded field name> <number>
  218. --     --   ------------------ --------
  219.  
  220. CHANGE NAME <existing field name> <new field name>
  221. --     -    --------------------- ----------------
  222.  
  223. FIELDS
  224. -
  225.  
  226. IV.  Examples
  227.  
  228. A.  Labels and Phone Lists
  229.     ----------------------
  230.  
  231.     Features and topics covered:
  232.  
  233.         File Definition
  234.         Coded Fields
  235.         Adding Data
  236.         Changing Data
  237.         Selection
  238.         Printing
  239.         Sorting
  240.         Rebuilding
  241.         Redefinition
  242.  
  243.     The  first  thing  that  one  needs  to  know how to do in any database
  244.     management system is the definition of the file.  Our first  example  a
  245.     simple  phone  list and label system.  Our file will store individuals'
  246.     name, address, city, state, zip code, and phone number.
  247.  
  248.         *NEW NAME.OLF
  249.         Enter #fields, #records 8,100
  250.         Field #1 ALPHA15,LAST_NAME:LN
  251.         Field #2 ALPHA15,FIRST_NAME:FN
  252.         Field #3 ALPHA30,ADDRESS:ADDR:A
  253.         Field #4 ALPHA20,CITY:CIT:C
  254.         Field #5 CODE "AL"="ALABAMA" "CA"="CALIFORNIA" &
  255.         ..  "IL"="ILLINOIS" "WI"="WISCONSIN",STATE:ST:S
  256.         Field #6 ALPHA5,ZIP:Z
  257.         Field #7 UNSIGNED,AREA_CODE:AC
  258.         Field #8 LONG,PHONE_NUMBER:PHONE:PN
  259.         File Defined
  260.         *
  261.  el+ZY first  field of the record is the individual's last name.  A field
  262.     name must begin with  a  letter,  and  can  contains  numbers  and  the
  263.     underscore  character  or a period.  The maximum space this file allows
  264.     for last names is fifteen alphanumeric characters.  There is  a  single
  265.     synonym  defined for last name.  It is the abbreviation "LN".  The next
  266.     three fields, first name, address,  and  city  are  variations  on  the
  267.     alphanumeric theme.
  268.  
  269.     Following  city  comes  a  coded  field.  A coded field allows input of
  270.     alphanumeric character strings from a predefined list.  Input can be in
  271.     short  or long form.  In the example, Alabama may be entered as "AL" or
  272.     as "ALABAMA".  The  use  of  coded  fields  is  appropriate  where  the
  273.     possible  inputs  are  obvious.   For example, the states of the United
  274.     States, the countries of the world, the products of a company,  or  the
  275.     colors  of  fabrics, are all things from lists which can be predefined.
  276.     Even if the list is subject to  change  the  use  of  coded  fields  is
  277.     recommended  because of the advantages.  One advantage is a significant
  278.     reduction in file size.  Smaller field size and file  size  results  in
  279.     more  efficiency  when OLAF needs to do a selection.  Another advantage
  280.     is the improvement of input, since only specific entries are  possible.
  281.     The  last  advantage cited here is that records can be summoned up in a
  282.     selection using abbreviation, saving keystrokes.  Other advantages will
  283.     be evident later.
  284.  
  285.     Following  the  coded  field  comes  a five character field for the zip
  286.     code, and following it comes the first completely numeric field for the
  287.     area  code.  The unsigned numeric allows positive number ranging from 0
  288.     through 65,235.  Finally, there is a long numeric field for  the  phone
  289.     number.
  290.  
  291.     Records  can  be  added  to a file interactively using the ADD command.
  292.     Type ADD and tap the carriage return key to start it.
  293.  
  294.         *add
  295.                LAST_NAME Levie
  296.               FIRST_NAME Jack
  297.                  ADDRESS 230 West Monroe
  298.                     CITY Chicago
  299.                    STATE IL
  300.                      ZIP 60690
  301.                AREA_CODE 312
  302.             PHONE_NUMBER 7822000
  303.         1 Record Added
  304.         *
  305.  
  306.     The  same record could be entered somewhat less interactively using the
  307.     BUILD command.  Type BUILD and tap return to get it started.
  308.  
  309.         *build
  310.         "Levie" "Jack" "230 W. Monroe" "Chicago" "IL" "60650" 312 7822000
  311.         ESC
  312.         1 Record Built
  313.         *
  314.  
  315.     The ESC symbol means  the  escape  key.   Control-Y  or  Control-Z  are
  316.     substitutes.   Any  one  of  the  three  indicates end of file to OLAF.
  317.     Entering records with the BUILD command may  be  slightly  faster  than
  318.     using  the  ADD  command,  however  it demands greater typing accuracy.
  319.     Note that many records at a time may be entered with the BUILD command.
  320.  
  321.  
  322.         *build
  323.         "Levie" "Jack" "230 W. Monroe" "Chicago" "IL" "60650" 312 7822000
  324.         "Kornbluh" "M." "230 Monroe" "Chicago" "IL" "60650" 312 7822000
  325.         "Fabry" "M." "230 Monroe" "Chicago" "IL" "60650" 312 7822000
  326.         ESC
  327.         2 Records Built
  328.         *
  329.  
  330.     The  third style of record entry is to use an editor to create an ASCII
  331.     file, then use the BUILD command to add the records to the  OLAF  file.
  332.     The  format  of  the  records  within  the ASCII file should follow the
  333.     format of the above example of the interactive BUILD command.
  334.  
  335.         *build data.tmp
  336.         30 Records Built
  337.         *
  338.  
  339.     There are three styles of the CHANGE command to fix records.  The first
  340.     is the mass change.
  341.  
  342.         *CHANGE IF ADDR = "230 Monroe" THEN {ADDR = "230 West Monroe"}
  343.         2 Records Changed
  344.         *
  345.  
  346.     Every  record  that  matches  the  condition  to  the left of THEN will
  347.     undergo the change defined within the brackets.
  348.  
  349.     The second style is the mass-interactive CHANGE.
  350.  
  351.         *CHANGE IF FN = "M." THEN {LN; FN = TTY FN}
  352.         Kornbluh
  353.               FIRST_NAME Marty
  354.         Fabry
  355.               FIRST_NAME Mike
  356.         2 Records Changed
  357.         *
  358.  
  359.     The mass-interactive CHANGE allows a different assignment of  some  new
  360.     values  for  every  record  that  satifies the condition to the left of
  361.     THEN.
  362.  
  363.     The interactive CHANGE is the third style.  In it, both  the  left  and
  364.     right sides of the command accept variable input.
  365.  
  366.         *CHA/REPEAT, FIND 1/IF LN = TTY LN THEN {ADDR; ZIP; &
  367.         ... ADDR = TTY ADDR; ZIP = TTY ZIP}
  368.                LAST_NAME Fabry
  369.         230 West Monroe         60690       ADDRESS 230 Monroe
  370.                      ZIP 60606
  371.         1 Records Changed
  372.                LAST_NAME Kornbluh           ADDRESS 230 Monroe
  373.         230 West Monroe         60690
  374.                      ZIP 60606
  375.         1 Records Changed
  376.                LAST_NAME ESC
  377.         0 Records Changed
  378.         *
  379.  
  380.     The escape character is again  the  means  to  tell  OLAF  to  end  the
  381.     session,  as  it  was in the BUILD command.  Note the options appearing
  382.     within the slashes.  REPEAT is the way to make the command execute  any
  383.     number of times.  In this example, the FIND option tells OLAF to select
  384.     only one record as a candidate for change.
  385.  
  386.     Reporting in OLAF  is  broken  into  three  primary  parts,  which  are
  387.     selecting, sorting, and printing.  Selecting is the part that retrieves
  388.     the records to be printed.
  389.  
  390.         *select if area_code = 312
  391.         3 Records Selected
  392.         *
  393.  
  394.     The  select  list  remains  unchanged  until  another SELECT command is
  395.     given, or another command is given that  can  alter  the  select  list.
  396.     Such  commands  are CHANGE and BULD.  ADD does not completely alter the
  397.     select list, but it appends to it.  SORT alters the order but  not  the
  398.     contents of the select list.
  399.  
  400.         *sort last_name; first_name ;
  401.         Sorting 3 Records.  Key is 32 bytes.  1 partitions.
  402.         *
  403.  
  404.     The sorted list awaits another PRINT command to show the results of its
  405.     work.
  406.  
  407.         *print ln; fn;
  408.         Fabry           Mike
  409.         Kornbluh        Marty
  410.         Levie           Jack
  411.         *
  412.  
  413.     The  select  list remains sorted until another SORT command changes its
  414.     order.  A SORT command can be issued without any key  references.   The
  415.     effect  of  the  keyless  sort is to return the select list back to its
  416.     original state.
  417.  
  418.     The following PRINT command shows how to print labels.  It makes liberal
  419.     use  of  abbreviations and a few special symbols.  Semicolons delineate
  420.     statements.  The circumflexes delineate print modifiers,  and  the  "v"
  421.     within  the  circumflexes  is an abbreviation of "variable", which is a
  422.     commonly  used  modifier  in   OLAF.    The   double   slash   is   the
  423.     carriage-return-line-feed symbol.  The backarrow is the backspace.
  424.  
  425.         *p ln^v^; <-; ","; fn; //; addr; //; city^v^; <-; ","; st^v^; &
  426.         .. zip; 3 * //
  427.         Fabry, Mike
  428.         230 W. Monroe
  429.         Schaumburg, ILLINOIS 60606
  430.  
  431.  
  432.  
  433.         Kornbluh, Marty
  434.         230 Monroe
  435.         Chicago, ILLINOIS 60606
  436.  
  437.  
  438.  
  439.         Levie, Jack
  440.         230 W. Monroe
  441.         Chicago, ILLINOIS 60690
  442.  
  443.  
  444.  
  445.         *
  446.  
  447.     It  might  be  imagined  that  for some reason the writer of the report
  448.     decides that it is unsatisfactory to  have  the  state  in  upper  case
  449.     characters.   What  can  be  done?   The CHANGE command can't solve the
  450.     problem  because  the  state  field  is  coded.   One  way to solve the
  451.     problem, using command already explained, is to rebuild the file.   The
  452.     following commands begin the job.
  453.  
  454.         *s 1=1
  455.         3 Records Selected
  456.         *p/to dat.tmp/ ""+ln+""; ""+fn+""; ""+a+""; ""+c+""; &
  457.         .. ""; <-; s^code^; <-; ""; ""+z+""; ac; pn
  458.         *f/to name.def/
  459.  
  460.     The first of the three above commands may seem peculiar.  In English it
  461.     says  "select  if  one equals one", which is a condition that is always
  462.     true.  This is a command that selects every record of a file regardless
  463.     of the values of the fields of the file.
  464.  
  465.     The  above  print  command shows the option for printing to devices and
  466.     files.  Note that the same option may be used to direct the output to a
  467.     printer (it would be "to prn:").
  468.  
  469.     An  intermediate  step  in  file rebuilding that can not be done within
  470.     OLAF is to use an editor to change the OLAF definition file created  by
  471.     the  FIELDS  command  in  the  last  of  the  above three steps.  After
  472.     editing, the file might look like the following.
  473.  
  474.         new NAME.OLF
  475.         8,100
  476.         ALPHA15,LAST_NAME:LN
  477.         ALPHA15,FIRST_NAME:FN
  478.         ALPHA30,ADDRESS:ADDR:A
  479.         ALPHA20,CITY:CIT:C
  480.         CODE/MULT  60 CODE  2 PNAME 20/ "AL"="Alabama" "CA"="California" &
  481.          "IN" = "Indiana" "IL"="Illinois" "WI"="Wisconsin",STATE:ST:S
  482.         ALPHA5,ZIP:Z
  483.         UNSIGNED/MIN 0 MAX 65535/,AREA_CODE:AC
  484.         LONG/MIN 0 MAX 0/,PHONE_NUMBER:PHONE:PN
  485.  
  486.     Note that Indiana is a new entry in the list of  states.   Redefinition
  487.     and  rebuilding  are the way to add to the coded lists.  The above file
  488.     definition shows some important definition options.   The  option  MULT
  489.     defines  the  maximum  number of entries that can be in the coded list.
  490.     This can be increased to a maximum of 255.  CODE 2 specifies  that  the
  491.     size of the code value, that which is to the left of the equal signs in
  492.     the list of entries, is two characters.  PNAME 20 means that the values
  493.     to  the  right of the equal signs may be as large as twenty characters.
  494.     Both the  CODE  and  PNAME  parameters  may  be  adjusted  as  desired.
  495.     Rebuilding is completed by the following two steps.
  496.  
  497.         *ex name.def
  498.         Enter #fields, #records
  499.         Field #1
  500.         Field #2
  501.         Field #3
  502.         Field #4
  503.         Field #5
  504.         Field #6
  505.         Field #7
  506.         Field #8
  507.         File Defined
  508.         *build dat.tmp
  509.         3 Records Built
  510.         *
  511.  
  512.     In the above rebuilding example only the coded list was changed.  If it
  513.     were necessary to add fields to the record, increase the  size  of  the
  514.     file,  or  alter  the  definition  of  a field, rebuilding could be the
  515.     solution.  However, there is another set of commands which  permit  the
  516.     redefinition of coded fields in a more convenient way.
  517.  
  518.         *redefine
  519.         >>change code state "ILLINOIS" = "Illinois"
  520.         >>change code state "ALABAMA" = "Alabama"
  521.         >>add code state "In" = "Indiana"
  522.         >>change code state "In" = "IN"
  523.         >>end
  524.         *
  525.  
  526.     Some  other  redefinition  of  files  short  of  complete rebuilding is
  527.     possible.  Fields can be added using the "ADD FIELDS"  command,  minima
  528.     and maxima can be changed, synonyms can be added for field names, field
  529.     names can be changed, and the "MULT" value of a  coded  field  can  be,
  530.     within  limits,  changed.   The limit is that the sum of the "code" and
  531.     "pname"  sizes  times  the  new  "MULT" and divided by 512 must yield a
  532.     quotient that is the same as the quotient  given  by  the  old  "MULT",
  533.     keeping  the  other values the same.  Redefinition can not change field
  534.     types, field sizes,  and  file  sizes.   Nor  can  redefinition  delete
  535.     fields.  Use rebuilding to solve such problems.
  536.  
  537.     To  resume the introduction to the PRINT command, here is an example of
  538.     a phone list.
  539.  
  540.         *s 1=1
  541.         3 Records Selected
  542.         *p ln + ", " + fn; 50 * "."; |50; ac^v^; <-; "-"; pn^v^
  543.         Fabry, Mike ......................................312-7822000
  544.         Levie, Jack ......................................312-7822000
  545.         Kornbluh, Marty ..................................312-7822000
  546.         *
  547.  
  548.     The phone list program shows concatenation of the last name, a comma, a
  549.     space,  and  the  first  name.  It shows an example of propogation of a
  550.     singe character.  It has a tab to column 50.  It also uses the variable
  551.     modifier in conjunction with two numeric fields.
  552.  
  553. B.  Statistics and a Histogram
  554.     --------------------------
  555.  
  556.     Features and topics covered:
  557.  
  558.         Arithmetic
  559.         Final
  560.         Heading
  561.         IF
  562.         Modifiers
  563.         Reset
  564.         Storing Programs
  565.         Summary Reporting
  566.         TTY Graphics
  567.         WHILE
  568.  
  569.     The  OLAF  programs  in this section use a file which has a field named
  570.     grade with a synonym of "g".  The range of possible scores is from zero
  571.     through one hundred.
  572.  
  573.     The first program is an example of summary reporting.  The objective is
  574.     to calculate the mean of all the grades.  It is not  important  to  see
  575.     the  details.   Therefore,  the  PRINT command's purpose is not to show
  576.     items but to sum the grades and the number of items in  the  set.   The
  577.     PRINT command uses the NOCARRIAGE option, which suppresses the carriage
  578.     control that normally follows the detail  line  of  print.   The  FINAL
  579.     command  is  an auxiliary print command.  OLAF executes the FINAL after
  580.     the last print detail line.  It is  a  good  habit  to  use  the  RESET
  581.     command.   Its  purpose  is  to free space for temporary variables.  It
  582.     erases OLAF's memory of temporary variables, auxiliary print  commands,
  583.     and procedures.
  584.  
  585.         *reset
  586.         *dec i count ;
  587.         *dec d sum, avg, var, varsq, sumvar;
  588.         *final avg = sum/count; "Count = "; count ; &
  589.         ..      "Sum ="; sum^7.2^; "Avg = "; avg^7.2^ ;
  590.         *s 1=1
  591.         46 Records Selected
  592.         *print/noc/sum = sum + g; count = count + 1;
  593.  
  594.         Count =           46 Sum = 3651.00 Avg =    79.37
  595.  
  596.     The next example uses another auxiliary print command:  the HEADING.  A
  597.     HEADING  executes before the first detail line and at regular intervals
  598.     as determined by the PAGE option of the PRINT command.   In  the  FINAL
  599.     command  following  the  variable  "sumvar"  there  are  two  new print
  600.     modifiers.  The "variable" modifier directs OLAF to leave as much space
  601.     as  needed  for  the  number and no more, and the "comma" modifier puts
  602.     commas into numbers at the proper places.
  603.  
  604.         *final "Total Variance ="; sumvar^15.2 var comma^; &
  605.         ..      "Standard Deviation ="; &
  606.         ..      ^/(sumvar/(count - 1))^7.2^ ;
  607.         *heading "Count"; |15; "Difference"; |30; "Diff. Squared"; //; &
  608.         ..       "-----"; |15; "----------"; |30; "-------------"
  609.         *print g; if g > avg then var = g - avg; else var = avg - g; &
  610.         ..      |15 ; var^10.2^ ; |30 ; varsq = var ** 2 ; &
  611.         ..      varsq^13.2^ ; &
  612.         ..      sumvar = sumvar + varsq ;
  613.  
  614.         Count          Difference     Diff. Squared
  615.         -----          ----------     -------------
  616.          78                  1.37              1.88
  617.          80                  0.63              0.40
  618.          85                  5.63             31.70
  619.           .                   .                 .
  620.           .                   .                 .
  621.           .                   .                 .
  622.          88                  8.63             74.48
  623.          86                  6.63             43.96
  624.          88                  8.63             74.48
  625.         Total Variance = 2,690.72 Standard Deviation =    7.73
  626.  
  627.     The final example of this section begins with a  HEADING  command  that
  628.     stands  alone.   OLAF  remembers auxiliary print commands from PRINT to
  629.     PRINT command.   Entering  HEADING  by  itself  makes  OLAF  discard  a
  630.     previously  entered  HEADING.   OLAF  provides a feature called "string
  631.     arithmetic".  The example shows that it is permissible to "multiply"  a
  632.     literal  and  an  integer  value.   The  effect is a propogation of the
  633.     literal.  The example shows that this feature makes it simple to  write
  634.     a histogram with OLAF.
  635.  
  636.         *heading
  637.         *dec i count[20], i ;
  638.         final i = 0; while i <= 20 do { i * 5;count[i]; &
  639.         ..      count[i] * "XX"; //; i = i + 1 };
  640.         print/noc/ i = g/5; count[i] = count[i] + 1 ;
  641.  
  642.           0           0  
  643.           5           0  
  644.          10           0  
  645.          15           0  
  646.          20           0  
  647.          25           0  
  648.          30           0  
  649.          35           0  
  650.          40           0  
  651.          45           0  
  652.          50           0  
  653.          55           1 XX 
  654.          60           0  
  655.          65           3 XXXXXX 
  656.          70           6 XXXXXXXXXXXX 
  657.          75          12 XXXXXXXXXXXXXXXXXXXXXXXX 
  658.          80           8 XXXXXXXXXXXXXXXX 
  659.          85          12 XXXXXXXXXXXXXXXXXXXXXXXX 
  660.          90           4 XXXXXXXX 
  661.          95           0  
  662.         100           0  
  663.  
  664.     OLAF command sequence can be stored in  files  using  an  editor.   The
  665.     EXECUTE  command  retrieves  a  file  containing  command sequences and
  666.     follows its directions.  Debugging a program is made easier  using  the
  667.     "noise"  option  with  the  EXECUTE  command.   OLAF  shows  the  files
  668.     instructions as it attempts to compile and execute them.   OLAF  points
  669.     to problems and gives error messages.
  670.  
  671.         *ex program.src
  672.  
  673. C.  Transaction Processing
  674.     ----------------------
  675.  
  676.     Features and topics covered:
  677.  
  678.         Sorting Alternatives
  679.         Multiple Files
  680.         Transaction Processing
  681.  
  682.     The example to be examined to introduce the application of  transaction
  683.     processing  in  OLAF  is  a  basic  order entry system.  The particular
  684.     system is imagined  to  be  for  a  furniture  retailer  who  keeps  an
  685.     inventory  of  fewer  than 256 basic items.  The retailer can therefore
  686.     use a coded field to describe the basic items he sells.  A  basic  item
  687.     can  have  a  variety  of  colors  and  textures.  A second coded field
  688.     describes  the  inventory  item in more detail.  An unsigned integer is
  689.     believed to be more than sufficient for the purpose  of  numbering  the
  690.     customers.   This  particular  retailer  gets most of his business from
  691.     fewer than 200 repeat business customers.  He can't imagine ever having
  692.     65,000  customers.  But if he someday decides to sell more aggressively
  693.     directly  to the public, a possible way of adjusting the system for the
  694.     new environment would be to change the customer number from an unsigned
  695.     field  to  a  long  field.   The  files  would,  of  course, need to be
  696.     redefined and rebuilt.
  697.  
  698.     The remaining fields of the order file concern the quantities  and  the
  699.     significant  dates  occuring  in  the life of an order item.  The order
  700.     date has a minimum value corresponding to the system's inception.   The
  701.     shipping  date,  shipped  quantity, and billing date are all unknown at
  702.     the time the order is entered, and are entered as zeroes.  These fields
  703.     are updated in the course of transaction processing.
  704.  
  705.     Every  three  months  there will be some special processing.  The order
  706.     file is large enough to hold 15,000 order line items, which is 50% more
  707.     than  the order line items this business has ever had in a quarter.  At
  708.     the end of every three months, a new order file will be  defined.   The
  709.     unfilled  orders  shall  be extracted from the old order file and built
  710.     into the new  file.   This  is  done  using  the  rebuilding  procedure
  711.     outlined in the above section on labels and phone lists.
  712.  
  713.         ORDER.OLF
  714.         8,15000
  715.         UNSIGNED/MIN 0 MAX 65535/,CUSTOMER:CUST:C
  716.         CODE/MULT  50 CODE  3 PNAME 30/ "AC"="ARM CHAIR" &
  717.          "AQ"="AQUARIUM STAND" "BBD"="BUTCHER BLOCK DESK" &
  718.          "BBT"="BUTCHER BLOCK TABLE" "BSH"="HIGH BOOK SHELVES" &
  719.          "BSL"="LOW BOOK SHELVES" "BWC"="BENT WOOD CHAIR" &
  720.          "CA"="CARPET" "CAF"="CAFETERIA TABLE" "CH"="CHAIR" &
  721.          "CHN"="CHANDELIER" "CON"="CONFERENCE TABLE" "CT"= &
  722.         "COFFEE TABLE" "CR"="CREDENZA" "CU"="CUBICAL TABLE" &
  723.          "DE"="DESK" "DES"="SECRETARY'S DESK" "DIR"="DIRECTOR'S CHAIR" &
  724.          "ED"="EXECUTIVE DESK" "FC"="FOLDING CHAIRS" "FL"= &
  725.         "FLOOR LAMP" "GLO"="GLOBE" "HIL"="HIGH INTENSITY LAMP" &
  726.          "LS"="LAMP STAND" "LSH"="LAMP SHADE" "MTD"="MARBLE TOPPED DESK" &
  727.          "MPH"="MARBLE PEN HOLDER" "PCA"="PADDED CHAIR WITH ARMS" &
  728.          "PCN"="PADDED CHAIR, NO ARMS" "PSC"="PARTITION CORNER SECITON" &
  729.          "PS4"="PARTITION SECTION: 4' x 4'" "PS8"="PARTITION SECTION: 8' x 4'" &
  730.          "PSD"="PARTITION CLOSET DOOR" "PSH"="PARTITION SHELVING" &
  731.          "RC"="RECLINING CHAIR" "RL"="READING LAMP" "SC"= &
  732.         "SWIVEL CHAIR" "SCR"="AUDIO-VISUAL SCREEN" "SO"= &
  733.         "SOFA" "TA"="TABLE" "TG"="GLASS TABLE" "TL"="TABLE LAMP" &
  734.          "TO"="OVAL TABLE" "TR"="ROUND TABLE" "TT"="TYPING TABLE",PRODUCT &
  735.         :PROD:P
  736.         CODE/MULT  60 CODE  3 PNAME 20/ " "=" " "BE"="BEIGE" "BLK"= &
  737.         "BLACK" "BLL"="LIGHT BLUE" "BLS"="BLACK STEEL" "BLU"="BLUE" &
  738.          "BP"="BLACK PLASTIC" "BR"="BROWN" "BRD"="LIGHT BROWN" "BRL"= &
  739.         "LIGHT BROWN" "BU"="BURGUNDY" "CAN"="CANVAS" "DA"="DARK" &
  740.          "DR"="DARK RED" "FAL"="LIGHT FABRIC" "FAD"="DARK FABRIC" &
  741.          "FW"="WHITE FABRIC" "FB"="BLACK FORMICA" "GR"="GREY" "GRD"= &
  742.         "DARK GREY" "GRL"="LIGHT GREY" "GRN"="GREEN" "GL"="LIGHT GREEN" &
  743.          "HI"="HIGH" "KH"="KHAKI" "LI"="LIGHT" "LV"="LIGNUM VITAE" &
  744.          "LO"="LOW" "MA"="MAPLE" "MAB"="BIRD'S EYE MAPLE" "MAU"= &
  745.         "MAUVE" "MH"="MAHOGANY" "OA"="OAK" "ORA"="ORANGE" "OR"= &
  746.         "ORIENTAL" "PE"="PERSIAN" "PI"="PINK" "PIN"="PINE" "PDS"= &
  747.         "DARK STAINED PINE" "PLS"="LIGHT STAINED PINE" "RE"="RED" &
  748.          "SP"="SPRUCE" "ST"="STEEL" "TK"="TEAK" "TKS"="STAINED TEAK" &
  749.          "WA"="WALNUT" "WAD"="DARK WALNUT" "WAL"="LIGHT WALNUT" &
  750.          "WF"="WHITE FORMICA" "WH"="WHITE" "WO"="WOOD" "YE"="YELLOW" &
  751.          "YEC"="CANARY YELLOW" "YP"="YELLOW PLASTIC",COLOR:COL:CO
  752.         SHORT/MIN 0 MAX 255/,QUANTITY:QUANT:Q
  753.         DATE/MIN  8OCT1985 MAX  8OCT1989/,ORDER_DATE:OD:O
  754.         DATE,SHIP_DATE:SD:S
  755.         DATE,BILL_DATE:BD:B
  756.         SHORT/MIN 0 MAX 255/,QUANTITY_SHIPPED:QS
  757.  
  758.     The  inventory  file  is large enough to contain 1,500 items.  For each
  759.     combination of product and color there should be exactly one record  in
  760.     the   inventory  file.   When  the  retailer  starts  to  carry  a  new
  761.     combination of product and color, he ADDs a  record  to  the  inventory
  762.     file.   When  he  buys  more  of  an  item  from  the  manufacturers or
  763.     wholesalers,  he CHANGEs the record in the inventory file for the item,
  764.     increasing the quantity.
  765.  
  766.         INVENT.OLF
  767.         4,1500
  768.         CODE/MULT  50 CODE  3 PNAME 30/ "AC"="ARM CHAIR" &
  769.                         .
  770.                         .   (same codes as in the order file)
  771.                         .
  772.          "TO"="OVAL TABLE" "TR"="ROUND TABLE" "TT"="TYPING TABLE",PRODUCT &
  773.         :PROD:P
  774.         CODE/MULT  60 CODE  3 PNAME 20/ " "=" " "BE"="BEIGE" "BLK"= &
  775.                         .
  776.                         .   (same codes as in the order file)
  777.                         .
  778.          "YEC"="CANARY YELLOW" "YP"="YELLOW PLASTIC",COLOR:COL:CO
  779.         UNSIGNED/MIN 0 MAX 65535/,QUANTITY:QUANT:Q
  780.         DOUBLE/DEC 2 MIN 0 MAX 0/,PRICE:PRI:PR
  781.  
  782.     How can the retailer be sure that there  is  only  one  record  in  the
  783.     inventory file for each combination of product and color?  After ADDing
  784.     records to the inventory file, he always runs a report that checks  for
  785.     duplicates.
  786.  
  787.         *select if 1=1
  788.         675 Records Selected
  789.         *dec a hold_p<30>, hold_co<20> ;
  790.         *sort p;co
  791.         Sorting 675 Records.  Key is 52 bytes.  3 partitions.
  792.         *p/noc/if p = hold_p and co = hold_co then {p;co;//}; &
  793.         .. hold_p = p; hold_co = co
  794.         CREDENZA                      OAK
  795.  
  796.     The  check  for  duplicates  detects  a single duplicates among the 675
  797.     records in the  file.   Note  that  in  the  declaration  of  temporary
  798.     variables care was taken to make the variables themselves big enough to
  799.     contain their corresponding fields.  If the size of an ALPHA  temporary
  800.     variable is not specified its default size is sixteen bytes.
  801.  
  802.     OLAF  is sensitive to techniques that improve efficiency.  In the above
  803.     duplicate check the SORT's reply says that the  key  is  52  characters
  804.     long  and  that  the  total contents of the sort fill three partitions.
  805.     This means that there is three times more data being pushed around than
  806.     can  fit into OLAF's main memory.  In a duplicate check it is important
  807.     to put the data into some kind of order, but the actual order does  not
  808.     matter, whether ascending, descending, or something else.  Coded fields
  809.     do, in fact, offer alternative ordering possibilities.  Here is another
  810.     sorting possibility for the duplicate check.
  811.  
  812.         *select if 1=1
  813.         675 Records Selected
  814.         *dec a hold_p<30>, hold_co<20> ;
  815.         *sort p^code^; co^code^
  816.         Sorting 675 Records.  Key is 8 bytes.  1 partitions.
  817.         *p/noc/if p = hold_p and co = hold_co then {p;co;//}; &
  818.         .. hold_p = p; hold_co = co
  819.         CREDENZA                      OAK
  820.  
  821.     In  a  test  of the two sorts, the first took 3 minutes and 17 seconds,
  822.     the second took 1 minute and 30 seconds.
  823.  
  824.     There is a third possibility in sorting coded fields.  It is to sort on
  825.     the  basis  of  the  coded value's position in the coded list.  This is
  826.     achieved as follows.
  827.  
  828.         *select if 1=1
  829.         675 Records Selected
  830.         *dec i tmp
  831.         *sort tmp = p; tmp; tmp = co; tmp
  832.         Sorting 675 Records.  Key is 24 bytes.  2 partitions.
  833.         *dec a hold_p<30>, hold_co<20> ;
  834.         *p/noc/if p = hold_p and co = hold_co then {p;co;//}; &
  835.         .. hold_p = p; hold_co = co
  836.         CREDENZA                      OAK
  837.  
  838.     This  sort  is  actually slower than the other two, because there is an
  839.     additional cost for  sorting  DOUBLEs,  LONGs,  FLOATs,  and  DATEs  as
  840.     compared to sorting SHORTs, ALPHAs, INTs, UNSIGNEDs.  A declared INT is
  841.     internally a LONG, and that is how it happens that the above sort works
  842.     with LONGs and becomes slower.  The sort of the test took 4 minutes and
  843.     50 seconds.
  844.  
  845.     Another desirable edit of the freshly entered data is to make sure that
  846.     the  product  color combination is good.  In other words, does a record
  847.     exist in the inventory file for the product color  combination  on  the
  848.     order  record?   To  perform  this kind of edit, it must be possible to
  849.     bring both the order and the inventory files together.   The  following
  850.     shows how to do it.
  851.  
  852.         *open order.olf, invent.olf
  853.         ORDER.OLF Retrieved
  854.         INVENT.OLF Rectieved
  855.         *dec a hold_p<30>, hold_co<20>
  856.         *dec i tmp
  857.         *proc check_select 2
  858.         CHECK_SELECT:: select/silence, find 1/if p = hold_p and &
  859.         .. co = hold_co
  860.         *proc check_print 2
  861.         CHECK_PRINT:: print/noc/tmp = 1
  862.         *select if sd = 0
  863.         20 Records Selected
  864.         *print/noc/tmp = 0; hold_p = p; hold_co = co; &
  865.         .. call check_select ; &
  866.         .. call check_print ; &
  867.         .. if tmp = 0 then { p; co; // }
  868.         CHANDELIER                    KHAKI
  869.  
  870.     The  edit  detects that there is no such product as a khaki chandelier.
  871.     The edit makes use of the procedure feature of OLAF to access two files
  872.     at  the same time.  A procedure has a name and a number that refers the
  873.     procedure to one of the opened files.  In  the  example  the  procedure
  874.     number  must  be one or two, because only two files are open.  OLAF may
  875.     open up to five OLAF files in the OPEN command.  A  procedure  contains
  876.     any  one  of  the  following kinds of commands:  SELECT, PRINT, CHANGE,
  877.     LET, DELETE, SORT.  In the above example two  procedures  are  declared
  878.     against the second file.  One uses a SELECT and the other uses a PRINT.
  879.     A procedure does not execute until it is called.  In the above example,
  880.     only records with no shipping date (sd =  0)  undergo  the  edit.   The
  881.     PRINT  command  loads  the  temporary  variables  with  values from the
  882.     selected records, and performs the calls to the  two  procedures.   The
  883.     CHECK_SELECT  procedure  tries  to  find a record in the inventory file
  884.     that matches the values of the variables, and the  CHECK_PRINT  command
  885.     sets  a flag to 1 to signal to the calling PRINT command that the match
  886.     was found.  The calling PRINT then checks the value of  the  flag,  and
  887.     prints out the product name and color when the test is negative.
  888.  
  889.     The  above  method using procedures is one way to perform the necessary
  890.     edit.  As stated before, OLAF is flexible.  There are often  many  ways
  891.     to  do  the  same  thing, and some ways are more efficient than others.
  892.     The following is a more efficient way  to  perform  the  same  edit  as
  893.     above.
  894.  
  895.         *open ORDER.OLF, INVENT.OLF
  896.         *dec a check<1>[3000] = "N"
  897.         *fil 2
  898.         INVENT.OLF Active
  899.         *select 1=1
  900.         675 Records Selected
  901.         *p/noc/check[p * 50 + co] = "Y"
  902.         *fil 1
  903.         ORDER.OLF Active
  904.         *select if check[p * 50 + co] != "Y"
  905.         1 Records Selected
  906.         *p p;co
  907.         CHANDELIER                    KHAKI
  908.  
  909.     The  above example uses a single large array to tie the files together.
  910.     After all, all the  edit  check  needs  is  some  indication  that  the
  911.     combination  is  valid.  This yes/no indication can be indicatee  above example uses a single large array to tie the files together.
  912.     After all, all the  edit  check  needs  is  some  indication  that  the
  913.     combination  is  valid.  This yes/no indication can be indicated in one
  914.     byte.  A three thousand cell array is declared, its  dimenion  derived
  915.     from  the  product of the dimensions of the two coded lists involved in
  916.     the combination.  The first print command in the  above  example  shows
  917.     that  the numeric property of a coded field may be used to advantage in
  918.     this problem.  A proper subscript into the array is the  numeric  value
  919.     of the product times fifty, which is the maximum possible value of  the
  920.     product  field (which we know from looking at the MULT parameter in the
  921.     FIELDS display), added to which is  the  numeric  value  of  the  color
  922.     field.
  923.  
  924.     OLAF  has  room  for  10,000  characters  of  array  space.   The array
  925.     declaration of the example uses 3,000 characters.
  926.  
  927.     Here  is a sample of unfilled orders.  This is how they look after they
  928.     are entered and before they undergo the  transaction  processing  steps
  929.     which seek to fill the orders.
  930.  
  931.         *s if sd = 0
  932.         20 Records Selected
  933.         *p c; if co != " " then co^v^; p^v^; |40; q; od; qs; sd
  934.             1 BEIGE ARM CHAIR                     1 14NOV85   0       0
  935.             1 BLACK AQUARIUM STAND                1 14NOV85   0       0
  936.             1 BUTCHER BLOCK DESK                  1 14NOV85   0       0
  937.             1 CHANDELIER                          1 14NOV85   0       0
  938.             2 YELLOW PLASTIC CAFETERIA TABLE      1 14NOV85   0       0
  939.             2 WHITE FORMICA CONFERENCE TABLE      1 14NOV85   0       0
  940.             3 BLACK HIGH BOOK SHELVES             2 14NOV85   0       0
  941.             3 BLACK LOW BOOK SHELVES              1 14NOV85   0       0
  942.             3 PINE BENT WOOD CHAIR                3 14NOV85   0       0
  943.             3 WOOD COFFEE TABLE                   1 14NOV85   0       0
  944.             3 MARBLE PEN HOLDER                   1 14NOV85   0       0
  945.             4 LIGHT WALNUT CREDENZA               1 14NOV85   0       0
  946.             4 LOW GLASS TABLE                     1 14NOV85   0       0
  947.             4 PINE BENT WOOD CHAIR                2 14NOV85   0       0
  948.             5 WHITE DIRECTOR'S CHAIR              3 14NOV85   0       0
  949.             6 GLOBE                               1 14NOV85   0       0
  950.           100 BEIGE PARTITION CORNER SECITON      1 14NOV85   0       0
  951.           100 BEIGE PARTITION SECTION: 4' x 4'    3 14NOV85   0       0
  952.           150 DARK WALNUT CREDENZA                1 14NOV85   0       0
  953.           200 BLACK SWIVEL CHAIR                  1 14NOV85   0       0
  954.  
  955.     The following is the heart of the order entry  system.   In  the  steps
  956.     below,  for  every  order  line  item  the  correct inventory record is
  957.     reduced, and the order item record itself is updated to show that it is
  958.     filled if and only if there is sufficient inventory to cover it.  Order
  959.     items  for  which  there  is  not  sufficient  inventory  simply remain
  960.     unchanged.
  961.  
  962.         *open order.olf,invent.olf
  963.         ORDER.OLF Retrieved
  964.         INVENT.OLF Retrieved
  965.         *dec a hold_p<30>, hold_co<20> ;
  966.         *dec date_today = 11nov85 ;
  967.         *dec i qty_wanted, tmp
  968.         *proc inventory_check 2
  969.         INVENTORY_CHECK:: change/find 1,nowrite, silence/ &
  970.         .. if product = hold_p and color = hold_co &
  971.         .. and q >= qty_wanted then &
  972.         ..  { q = q - qty_wanted; tmp = 1 }
  973.         *change if sd = 0 then { hold_p = product ; &
  974.         ..  hold_co = color; qty_wanted = quantity ; &
  975.         ..  tmp = 0 ; call inventory_check; &
  976.         ..  if tmp = 1 then {sd = today; qs = quantity}; }
  977.         19 Records Changed
  978.  
  979.     The  above  sequence of commands makes use of a procedure, whose change
  980.     command has three  options.   The  first  option,  "FIND  1",  improves
  981.     efficiency  because  it  tells  OLAF  to  stop searching the file after
  982.     finding the first match.  The second option, "NOWRITE", has  effect  if
  983.     and  only  if  a CHANGE command is used within a procedure.  Normally a
  984.     CHANGE command writes to the file after it has found all  its  matches.
  985.     The "NOWRITE" option directs the CHANGE to suspend its writes until the
  986.     completion  of  the  calling  command.   The "SILENCE" option tells the
  987.     CHANGE to not report its results after its execution, which would occur
  988.     every time it is called.
  989.  
  990.     Here is how the orders look after attempt to fill them.
  991.  
  992.         *s if od = 14nov85
  993.         20 Records Selected
  994.         *p c; if co != " " then co^v^; p^v^; |40; q; od; qs; sd
  995.             1 BEIGE ARM CHAIR                     1 14NOV85   1 14NOV85
  996.             1 BLACK AQUARIUM STAND                1 14NOV85   1 14NOV85
  997.             1 BUTCHER BLOCK DESK                  1 14NOV85   1 14NOV85
  998.             1 CHANDELIER                          1 14NOV85   1 14NOV85
  999.             2 YELLOW PLASTIC CAFETERIA TABLE      1 14NOV85   1 14NOV85
  1000.             2 WHITE FORMICA CONFERENCE TABLE      1 14NOV85   0       0
  1001.             3 BLACK HIGH BOOK SHELVES             2 14NOV85   2 14NOV85
  1002.             3 BLACK LOW BOOK SHELVES              1 14NOV85   1 14NOV85
  1003.             3 PINE BENT WOOD CHAIR                3 14NOV85   3 14NOV85
  1004.             3 WOOD COFFEE TABLE                   1 14NOV85   1 14NOV85
  1005.             3 MARBLE PEN HOLDER                   1 14NOV85   1 14NOV85
  1006.             4 LIGHT WALNUT CREDENZA               1 14NOV85   1 14NOV85
  1007.             4 LOW GLASS TABLE                     1 14NOV85   1 14NOV85
  1008.             4 PINE BENT WOOD CHAIR                2 14NOV85   2 14NOV85
  1009.             5 WHITE DIRECTOR'S CHAIR              3 14NOV85   3 14NOV85
  1010.             6 GLOBE                               1 14NOV85   1 14NOV85
  1011.           100 BEIGE PARTITION CORNER SECITON      1 14NOV85   1 14NOV85
  1012.           100 BEIGE PARTITION SECTION: 4' x 4'    3 14NOV85   3 14NOV85
  1013.           150 DARK WALNUT CREDENZA                1 14NOV85   1 14NOV85
  1014.           200 BLACK SWIVEL CHAIR                  1 14NOV85   1 14NOV85
  1015.  
  1016.     One  of  them  is  not  filled.  Probing the inventory file reveals the
  1017.     reason.  The stock of white formica  conference  tables  is  completely
  1018.     gone.
  1019.  
  1020.         *s if q = 0
  1021.         1 Records Selected
  1022.         *p TITION CORNER SECITON      1 14NOV85   1 14NOV85
  1023.           100 BEIGE PARTITION SECTION: 4' x 4'    3 14NOV85   3 14NOV85
  1024.           150 DARK WALNUT CREDENZA                1 14NOV85   1 14NOV85
  1025.           200 BLACK SWIVEL CHAIR                  1 14NOV85   1 14NOV85
  1026.  
  1027.     One  of  them  is  not  filled.  Probing the inventory file reveals the
  1028.     reason.  The stock of white formica  conference  tables  is  completely
  1029.     gone.
  1030.  
  1031.         *s if q = 0
  1032.         1 Records Selected
  1033.         *p co; p
  1034.         WHITE FORMICA       CONFERENCE TABLE
  1035.  
  1036.     Te next example is much the same, but in this  case  order  items  are
  1037.     filled on a first in first out basis.
  1038.  
  1039.         *open order.olf,invent.olf,order.olf
  1040.         ORDER.OLF Retrieved
  1041.         INVENT.OLF Retrieved
  1042.         ORDER.OLF Retrieved
  1043.         *dec a hold_p<30>, hold_co<20>;
  1044.         *dec date today = 11nov85 ;
  1045.         *dec i qty_wanted, hold_customer ;
  1046.         *proc update_order 3
  1047.         UPDATE_ORDER:: change/find 1, nowrite, silence/
  1048.         ..      if product = hold_p &
  1049.         ..      and color = hold_co &
  1050.         ..      and customer = hold_customer and qs = 0 then &
  1051.         ..        { qs = qty_wanted ; ship_date = today }
  1052.         *proc inventory_check 2
  1053.         INVENTORY_CHECK:: change/find 1,nowrite, silence/ &
  1054.         ..      if product = hold_p &
  1055.         ..      and color = hold_co &
  1056.         ..      and q >= qty_wanted then &
  1057.         ..        { q = q - qty_wanted; call update_order }
  1058.         *select if ship_date = 0
  1059.         20 Records Selected
  1060.         *sort order_date
  1061.         Sorting 20 Records.  Key is 6 bytes.  1 Partitions.
  1062.         *print/noc/ hold_customer = customer ; hold_p = product ; &
  1063.         ..  hold_co = color; qty_wanted = quantity ; &
  1064.         ..  call inventory_check
  1065.         *
  1066.  
  1067.     The  order file is opened twice in the above command sequence.  This is
  1068.     permissible as long as the updating happens through only one channel to
  1069.     the file as long as it is open.  In the example, ORDER.OLF is both file
  1070.     1 and file 3.  File 3 is the one that is updated.  File 1 must never be
  1071.     updated.  In fact, immediately following the final step above it  would
  1072.     be  a  good  practice to give another OPEN command.  This would protect
  1073.     the changes made to ORDER.OLF.
  1074.  
  1075. D.  Scheduling Programs and a Gantt Chart
  1076.     -------------------------------------
  1077.  
  1078.     Features covered:
  1079.  
  1080.         Date Arithmetic
  1081.         Date Modifiers
  1082.         Alpha Arithmetic
  1083.  
  1084.     OLAF's  date  arithmetic  feature  can be used in coordination with its
  1085.     transaction processing ability  as  the  foundation  for  a  scheduling
  1086.     system.  Such a system might begin with a file defined as follows:
  1087.  
  1088.         SCHEDULE.OLF
  1089.         6,100,15,0
  1090.         ALPHA5,ACTIVITY:A
  1091.         ALPHA30,DESCRIPTION:DES:D
  1092.         SHORT/MIN 0 MAX 255/,TIME:T
  1093.         SHORT/MIN 0 MAX 255/,PRIORITY:P
  1094.         DATE,START:S
  1095.         DATE,END:E
  1096.  
  1097.     In this demonstration, the records of the file describe  activities  in
  1098.     the construction of a house.  The records are captured with their start
  1099.     and dates set to 0.
  1100.  
  1101.         *s 1=1
  1102.         15 Records Selected
  1103.         p a; description; time; priority
  1104.         A1    DIG HOLE                        10   0
  1105.         A2    FORM FOOTINGS                    5  10
  1106.         A3    POUR FOOTINGS                    1  20
  1107.         A4    FORM FOUNDATION WALLS           10  30
  1108.         A5    BRACE FOUNDATION WALLS           2  40
  1109.         A6    POUR FOUNDATION WALLS            1  50
  1110.         A7    FRAME WALLS                     10  60
  1111.         A8    FRAME ROOF                       7  70
  1112.         A9    DO FLOORING                      2  60
  1113.         A10   EXTERIOR WALLS                   7  70
  1114.         A11   CEILINGS                         5  70
  1115.         A12   DRY WALL                         5  70
  1116.         A13   ROOFING                          1  80
  1117.         A14   PAINT                            5  90
  1118.         A15   MOVE IN                          3 100
  1119.  
  1120.     The starting date of the  project  is  declared  in  a  variable  named
  1121.     "today".   In  this  schedule,  it  is assumed that activities must not
  1122.     overlap.
  1123.  
  1124.         *o schedule.olf, schedule.olf
  1125.         SCHEDULE.OLF Retrieved
  1126.         SCHEDULE.OLF Retrieved
  1127.         *dec date today = 14nov85
  1128.         *dec a hold_a
  1129.         *proc update 2
  1130.         UPDATE:: change/find 1, silence, nowrite/ &
  1131.         ..if a = hold_a then {s = today; today = today + t; e = today}
  1132.         *s 1=1
  1133.         15 Records Selected
  1134.         *sort p
  1135.         Sorting 15 Records.  Key is 3 bytes.  1 partitions.
  1136.         *print/noc/hold_a = a; call update
  1137.  
  1138.     Here is the result of the above  scheduling  sequence.   Note  that  an
  1139.     activity  begins  when  its  predecessor  ends.   The  priority   field
  1140.     establishes the ordering of the activities.  Note that the report shows
  1141.     a print modifier that can be used with dates.
  1142.  
  1143.         *sort s
  1144.         Sorting 15 Records.  Key is 13 bytes.  1 partitions.
  1145.         *p a; d; t; p; s^mm/dd/yy^; e^mm/dd/yy^
  1146.         A1    DIG HOLE                        10   0 14NOV1985 24NOV1985
  1147.         A2    FORM FOOTINGS                    5  10 24NOV1985 29NOV1985
  1148.         A3    POUR FOOTINGS                    1  20 29NOV1985 30NOV1985
  1149.         A4    FORM FOUNDATION WALLS           10  30 30NOV1985 10DEC1985
  1150.         A5    BRACE FOUNDATION WALLS           2  40 10DEC1985 12DEC1985
  1151.         A6    POUR FOUNDATION WALLS            1  50 12DEC1985 13DEC1985
  1152.         A7    FRAME WALLS                     10  60 13DEC1985 23DEC1985
  1153.         A8    FRAME ROOF                       7  70 25DEC1985  1JAN1986
  1154.         A9    DO FLOORING                      2  60 23DEC1985 25DEC1985
  1155.         A10   EXTERIOR WALLS                   7  70  1JAN1986  8JAN1986
  1156.         A11   CEILINGS                         5  70  8JAN1986 13JAN1986
  1157.         A12   DRY WALL                         5  70 13JAN1986 18JAN1986
  1158.         A13   ROOFING                          1  80 18JAN1986 19JAN1986
  1159.         A14   PAINT                            5  90 19JAN1986 24JAN1986
  1160.         A15   MOVE IN                          3 100 24JAN1986 27JAN1986
  1161.  
  1162.     Perhaps  it  is an unreasonable restriction that activities be strictly
  1163.     sequential.  The following command sequence allows acitivities  of  the
  1164.     same priority to be worked on concurrently.
  1165.  
  1166.         *o schedule.olf, schedule.olf
  1167.         SCHEDULE.OLF Retrieved
  1168.         SCHEDULE.OLF Retrieved
  1169.         *dec date today = 14nov85, max_date
  1170.         *dec i last_p = -1
  1171.         *dec a hold_a
  1172.         *proc update 2
  1173.         UPDATE:: change/find 1, nowrite/if a = hold_a then &
  1174.         ..      { s = today; e = s + t; &
  1175.         ..      if e > max_date then { max_date = e  } ; } ;
  1176.         *s 1=1
  1177.         15 Records Selected
  1178.         *sort p
  1179.         Sorting 15 Records.  Key is 3 bytes.  1 partitions.
  1180.         *prin/noc/ if p != last_p and max_date != 0 then &
  1181.         .. today = max_date; hold_a = a; call update; last_p = p
  1182.  
  1183.     The following report shows the results.  Note the new date modifier for
  1184.     the popular mm/dd/yy date format.
  1185.  
  1186.         *sort s; e
  1187.         Sorting 15 Records.  Key is 24 bytes.  1 partitions.
  1188.         *p a; d; t; p; s^mm/dd/yy^; e^mm/dd/yy^
  1189.         A1    DIG HOLE                        10   0 11/14/85 11/24/85
  1190.         A2    FORM FOOTINGS                    5  10 11/24/85 11/29/85
  1191.         A3    POUR FOOTINGS                    1  20 11/29/85 11/30/85
  1192.         A4    FORM FOUNDATION WALLS           10  30 11/30/85 12/10/85
  1193.         A5    BRACE FOUNDATION WALLS           2  40 12/10/85 12/12/85
  1194.         A6    POUR FOUNDATION WALLS            1  50 12/12/85 12/13/85
  1195.         A7    FRAME WALLS                     10  60 12/13/85 12/23/85
  1196.         A8    FRAME ROOF                       7  70 12/23/85 12/30/85
  1197.         A9    DO FLOORING                      2  60 12/13/85 12/15/85
  1198.         A10   EXTERIOR WALLS                   7  70 12/23/85 12/30/85
  1199.         A11   CEILINGS                         5  70 12/23/85 12/28/85
  1200.         A12   DRY WALL                         5  70 12/23/85 12/28/85
  1201.         A13   ROOFING                          1  80 12/30/85 12/31/85
  1202.         A14   PAINT                            5  90 12/31/85  1/05/86
  1203.         A15   MOVE IN                          3 100  1/05/86  1/08/86
  1204.  
  1205.     It's always good to have a picture in a project management system.  The
  1206.     following  command  sequence  shows how to produce a Gantt chart.  Some
  1207.     extra effort was put into it to keep it narrow enough to fit within the
  1208.     margins  of  this  document.   It  makes  use  of alpha arithmetic.  An
  1209.     important rule in alpha arithmetic is that expressions must be kept
  1210.     very simple when alpha fields and literals are combined with nonalphas.
  1211.     This  means  that  there  can  be  only one nonalpha in the expression.
  1212.     Including more than one nonalpha confuses the compiler.  To work within
  1213.     the  restricition,  put the results of numeric or date expressions into
  1214.     temporary variables.
  1215.  
  1216.         *dec i tmp, len
  1217.         *print tmp = s - 14nov85; len = e - s; &
  1218.         ..      if tmp > 30 then &
  1219.         ..         {d; |30; tmp = tmp - 30; [] * tmp ; "x" * len} &
  1220.         ..      else &
  1221.         ..         { [] * tmp; "x" * len; |45; d}
  1222.  
  1223.          xxxxxxxxxx                                  DIG HOLE
  1224.                    xxxxx                             FORM FOOTINGS
  1225.                         x                            POUR FOOTINGS
  1226.                          xxxxxxxxxx                  FORM FOUNDATION WALLS
  1227.                                    xx                BRACE FOUNDATION WALLS
  1228.                                      x               POUR FOUNDATION WALLS
  1229.                                       xx             DO FLOORING
  1230.                                       xxxxxxxxxx     FRAME WALLS
  1231.         CEILINGS                                xxxxx
  1232.         DRY WALL                                xxxxx
  1233.         FRAME ROOF                              xxxxxxx
  1234.         EXTERIOR WALLS                          xxxxxxx
  1235.         ROOFING                                        x
  1236.         PAINT                                           xxxxx
  1237.         MOVE IN                                              xxx
  1238.  
  1239. E.  Sorting Totals
  1240.     --------------
  1241.  
  1242.     Feature covered:
  1243.  
  1244.         Calling procs out of SORT
  1245.  
  1246.     Sort has more flexibility than the prior examples have shown.   It  can
  1247.     call  procedures  and  use  IF's,  ELSE's, literal fields, and WHILE's.
  1248.     This sectio will develop the idea of  using  procedures  to  solve  the
  1249.     commonly  encountered  data  processing need to sort on a value that no
  1250.     data base records contain.
  1251.  
  1252.     The  problem  to  solve  is  to  sort  the  states of the U.S.  and the
  1253.     provinces of CANADA in order of the number  of  major  league  baseball
  1254.     teams that they contain, showing the state with the most first.   There
  1255.     are  two files.  The first contains a record for each team.  The second
  1256.     contains  a  single  record  for  each  state  that  contains  a  team.
  1257.     Respectively, the two file definitions are:
  1258.  
  1259.         TEAMS.OLF
  1260.         3,100,27,1
  1261.         CODE/MULT  50 CODE  2 PNAME 16/ "AL"="ALABAMA" "AK"="ALASKA" &
  1262.          "AR"="ARKANSAS" "AZ"="ARIZONA" "CA"="CALIFORNIA" "CN"="CONNECTICUT" &
  1263.          "DE"="DELAWARE" "GA"="GEORGIA" "ID"="IDAHO" "IA"="IOWA" "IL"= &
  1264.         "ILLNOIS" "IN"="INDIANA" "KY"="KENTUCKY" "LA"="LOUISIANA" "MA"= &
  1265.         "MASSACHUSETTS" "MD"="MARYLAND" "ME"="MAINE" "MI"="MICHIGAN" &
  1266.          "MN"="MINNESOTA" "MO"="MISSOURI" "NE"="NEBRASKA" "NH"="NEW HAMPSHIRE" &
  1267.          "NM"="NEW MEXICO" "NV"="NEVADA" "NY"="NEW YORK" "NC"="NORTH CAROLINA" &
  1268.          "ND"="NORTH DAKOTA" "OH"="OHIO" "OK"="OKLAHOMA" "ON"="ONTARIO" &
  1269.          "OR"="OREGON" "PA"="PENNSYLVANIA" "QU"="QUEBEC" "RI"="RHODE ISLAND" &
  1270.          "SC"="SOUTH CAROLINA" "SD"="SOUTH DAKOTA" "TN"="TENNESSEE" "TX"= &
  1271.         "TEXAS" "UT"="UTAH" "VI"="VIRGINIA" "VT"="VERMONT" "WA"="WASHINGTON" &
  1272.          "WV"="WEST VIRGINIA" "WI"="WISCONSIN" "WY"="WYOMING",STATE:STA &
  1273.         :ST:S
  1274.         ALPHA20,CITY:C
  1275.         ALPHA20,TEAM:T
  1276.  
  1277.         STATE.OLF
  1278.         1,60,16,0
  1279.         CODE/MULT  50 CODE  2 PNAME 16/ "AL"="ALABAMA" "AK"="ALASKA" &
  1280.                         .
  1281.                         .  (states are as shown in TEAMS.OLF)
  1282.                         .
  1283.         "WI"="WISCONSIN" "WY"="WYOMING",STATE:STA:ST:S
  1284.  
  1285.     The  following  command  sequence shows how SORT, using CALLS to select
  1286.     the teams and count them, can fabricate a key which it can then employ.
  1287.     The  key  appears  with  a  modifier to indicate that the key should be
  1288.     sorted in descending order.
  1289.  
  1290.         *open state.olf, teams.olf
  1291.         STATE.OLF Retrieved
  1292.         TEAMS.OLF Retrieved
  1293.         *dec a hold
  1294.         *dec i team_cnt = 0
  1295.         *proc sel 2
  1296.         SEL::select/silence/if hold = state
  1297.         *proc pri 2
  1298.         PRI::print/noc/team_cnt = team_cnt + 1
  1299.         *select 1=1
  1300.         16 Records Selected
  1301.         *sort hold = state; call sel; team_cnt=0; call pri; team_cnt^des^
  1302.         Sorting 16 Records.  Key is 13 bytes.  1 partitions.
  1303.         *heading  "State"; |30; "Nbr Teams"; //; &
  1304.                   "-----"; |30; "---------"
  1305.         *print hold = state; call sel; team_cnt = 0; call pri; state; &
  1306.         ..|24; team_cnt
  1307.  
  1308.         State                         Nbr Teams
  1309.         -----                         ---------
  1310.         CALIFORNIA                        5
  1311.         ILLNOIS                           2
  1312.         MISSOURI                          2
  1313.         NEW YORK                          2
  1314.         OHIO                              2
  1315.         PENNSYLVANIA                      2
  1316.         TEXAS                             2
  1317.         GEORGIA                           1
  1318.         MARYLAND                          1
  1319.         MASSACHUSETTS                     1
  1320.         MICHIGAN                          1
  1321.         MINNESOTA                         1
  1322.         ONTARIO                           1
  1323.         QUEBEC                            1
  1324.         WASHINGTON                        1
  1325.         WISCONSIN                         1
  1326.  
  1327.         A variation of the above command sequence makes it possible to
  1328.         see the teams that belong to each state.
  1329.  
  1330.         *open state.olf, teams.olf
  1331.         *dec a hold
  1332.         *dec i team_cnt = 0
  1333.         *proc sortsel 2
  1334.         SORTSEL::select/silence/if hold = state
  1335.         *proc sortprint 2
  1336.         SORTPRINT::print/noc/team_cnt = team_cnt + 1
  1337.         *select 1=1
  1338.         16 Records Selected
  1339.         *sort hold = state; call sortsel; team_cnt = 0; call sortprint; &
  1340.         ..team_cnt^des^
  1341.         Sorting 16 Records.  Key is 13 bytes.  1 partitions.
  1342.         *heading  "State"; |30; "Nbr Teams"; //; &
  1343.                   "-----"; |30; "---------"
  1344.         *proc showteams 2
  1345.         SHOWTEAMS::print |15; team
  1346.         *print hold = state; call sortsel; team_cnt = 0; call sortprint; &
  1347.         ..state; |24; team_cnt; //; call showteams
  1348.  
  1349.         State                         Nbr Teams
  1350.         -----                         ---------
  1351.         CALIFORNIA                        5
  1352.                        A'S
  1353.                        ANGELS
  1354.                        DODGERS
  1355.                        GIANTS
  1356.                        PADRES
  1357.  
  1358.         ILLNOIS                           2
  1359.                        CUBS
  1360.                        WHITE SOX
  1361.  
  1362.         MISSOURI                          2
  1363.                        CARDINALS
  1364.                        ROYALS
  1365.  
  1366.         NEW YORK                          2
  1367.                        METS
  1368.                        YANKEES
  1369.  
  1370.         OHIO                              2
  1371.                        INDIANS
  1372.                        REDS
  1373.  
  1374.         PENNSYLVANIA                      2
  1375.                        PHILLIES
  1376.                        PIRATES
  1377.  
  1378.         TEXAS                             2
  1379.                        RANGERS
  1380.                        ASTROS
  1381.  
  1382.         GEORGIA                           1
  1383.                        BRAVES
  1384.  
  1385.         MARYLAND                          1
  1386.                        ORIOLES
  1387.  
  1388.         MASSACHUSETTS                     1
  1389.                        RED SOX
  1390.  
  1391.         MICHIGAN                          1
  1392.                        TIGERS
  1393.  
  1394.         MINNESOTA                         1
  1395.                        TWINS
  1396.  
  1397.         ONTARIO                           1
  1398.                        BLUE JAYS
  1399.  
  1400.         QUEBEC                            1
  1401.                        EXPOS
  1402.  
  1403.         WASHINGTON                        1
  1404.                        MARINERS
  1405.  
  1406.         WISCONSIN                         1
  1407.                        BREWERS
  1408.  
  1409. V.  Disclaimer
  1410.  
  1411.     The Author will not be liable to you for any  damages,  including  lost
  1412.     profits,  lost  savings,  or  other incidental or consequential damages
  1413.     arising out of the use of or the inability to use these programs, event
  1414.     if  the  Author has been advised of the possibility of such damages, or
  1415.     for any claim by any other party.
  1416.